
#include "StdAfx.h"
#include "ShellConnect.h"
#include <stdio.h>
#include <stdlib.h>

ShellConnect::ShellConnect(){
}

ShellConnect::~ShellConnect(){
}

int ShellConnect::command( const char* cmd ){
	FILE* fp = 0;
    char buff[DEF_BUFFER_SIZE];

#ifdef WIN32
    fp = _popen( cmd, "r" );
#else
	fp = popen( cmd, "r" );
#endif

    if(! fp )
		return -1;

    while( fgets(buff, DEF_BUFFER_SIZE, fp) )
		buffer_ = buffer_ + buff;

#ifdef WIN32
	_pclose( fp );
#else
    pclose( fp );
#endif

	return buffer_.size();
}

const char* ShellConnect::getBuffer(){
	return buffer_.c_str();
}
